<html>

<head>
    <meta charset="UTF-8">
    <title>新建设备台账</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../../layui/css/layui.css"/>
    <link rel="stylesheet" href="../../css/bass.css"/>
    <link rel="stylesheet" href="../../css/city-picker.css"/>
    <style type="text/css">
        .layui-input-block {
            margin-left: 78px;
        }
        
        .city-picker-dropdown{
            left: -148px !important;
        }
    </style>
</head>

<body>
<div class="body">
    <header class="layui-nav" id="headerTop"></header>
    <div class="left_muen" id="left_menu"></div>
    <div class="content_body">
        <!--标题栏-->
        <p class="content_title">设备台账列表 &nbsp;&nbsp;>&nbsp;&nbsp;新建设备台账</p>
        <!--标题栏-->
        <form class="layui-form mt20">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">设备名称</label>

                    <div class="layui-input-inline">
                        <input type="text" name="jiqiname" autocomplete="off"  placeholder="请输入设备名称"  lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">设备编号</label>

                    <div class="layui-input-inline">
                        <input type="text" name="jiqicode" lay-verify="required" placeholder="请输入设备编号"  autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">设备分类</label>

                    <div class="layui-input-inline">
                        <select name="jiqimodules" lay-verify="required" lay-search="">
                            <option value="涡轮流量计">涡轮流量计</option>
                            <option value="超声波流量计">超声波流量计</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">设备状态&nbsp;&nbsp;</label>
                    <div class="layui-input-inline">
                        <select name="jiqistatus" lay-verify="required" lay-search="">
                            <option value="0">使用中</option>
                            <option value="1">禁用</option>
                            <option value="2">告警</option>
                            <option value="3">离线</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">设备类型</label>

                    <div class="layui-input-inline">
                        <select name="jiqiclassfi" lay-verify="required" lay-search="">
                            <option value="空">空</option>
                            <option value="计量仪器">计量仪器</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">设备条码</label>

                    <div class="layui-input-inline">
                        <input type="text" name="jiqiercode" placeholder="请输入设备条码" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">安装地点</label>

                    <div class="layui-input-inline">
                        <select name="jiqiposi" lay-verify="required" lay-search="">
                            <option value="门站">门站</option>
                            <option value="调压站">调压站</option>
                            <option value="LNG站">LNG站</option>
                            <option value="电厂">电厂</option>
                            <option value="直供用户">直供用户</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">安装位置&nbsp;&nbsp;</label>
                    <div class="layui-input-inline">
                        <!--<input readonly type="text" name="jiqiaddress" class="layui-input"-->
                               <!--data-toggle="city-picker" placeholder="点击从下拉面板中选择省/市/区/县" id="city-picker1">-->
                        <!--<div style="position:relative;">-->
                            <input readonly type="text" name="jiqiaddress" lay-verify="required" class="layui-input" id="target" data-toggle="city-picker" value="江苏省/常州市/溧阳市">
                        <!--</div>-->
                        <!--<input type="text" name="jiqiaddress" readonly autocomplete="off" data-toggle="city-picker" class="layui-input">-->
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">设备型号</label>

                    <div class="layui-input-inline">
                        <input type="text" name="jiqixinghao" placeholder="请输入设备型号" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">设备规格</label>

                    <div class="layui-input-inline">
                        <input type="text" name="jiqiguige" lay-verify="required" placeholder="请输入设备规格" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">设备位号</label>

                    <div class="layui-input-inline">
                        <input type="text" name="jiqiweihao" lay-verify="required" placeholder="请输入设备位号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" style="padding-right: 10px">设备父位号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="jiqifuweihao" placeholder="请输入设备父位号" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">供应商&nbsp;&nbsp;&nbsp;&nbsp;</label>

                    <div class="layui-input-inline">
                        <select name="jiqishanghu" lay-verify="required" lay-search="" id="deviceParentPositionNum">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">设备厂商</label>

                    <div class="layui-input-inline">
                        <select name="jiqichangshang" lay-search="" id="deviceProducer">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">到货时间</label>

                    <div class="layui-input-block">
                        <input type="text" name="daohuoshijian" id="date1" lay-verify="date" placeholder="请选择时间"
                               autocomplete="off" class="layui-input" style="width: 93%">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">使用时间</label>

                    <div class="layui-input-block">
                        <input type="text" name="shiyongshijian" id="date2" lay-verify="date" placeholder="请选择时间"
                               autocomplete="off" class="layui-input" style="width: 96%">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">报废时间</label>

                    <div class="layui-input-block">
                        <input type="text" name="baofeishijian" id="date3" lay-verify="date" placeholder="请选择时间"
                               autocomplete="off" class="layui-input" style="width: 95%">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">设备用途</label>

                    <div class="layui-input-inline">
                        <input type="text" name="jiqiyongtu"  placeholder="请输入设备用途" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">出厂编号</label>

                    <div class="layui-input-inline">
                        <input type="text" name="chuchangbiaohao" placeholder="请输入出厂编号" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">出厂日期</label>

                    <div class="layui-input-block">
                        <input type="text" name="chuchangriqi" id="date4" lay-verify="date" placeholder="请选择时间"
                               autocomplete="off" class="layui-input" style="width: 97%">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">责任部门</label>

                    <div class="layui-input-inline">
                        <input type="text" name="zerenbumen" placeholder="请输入责任部门" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">&nbsp;&nbsp;负责人&nbsp;&nbsp;</label>

                    <div class="layui-input-inline">
                        <input type="text" name="fuzeren" lay-verify="required" placeholder="请输入负责人" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">购置价值</label>
                    <div class="layui-input-inline">
                        <input type="text" name="gouzhijiazhi" lay-verify="required|number" placeholder="请输入购置价值" autocomplete="off" class="layui-input">
                    </div>
                    <label class="layui-form-label" style="padding-left: 2px">(元)</label>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block" style="width: 61%">
                    <textarea placeholder="请输入内容" class="layui-textarea" id="lay_beizhu"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <div class="layui-btn" lay-submit="" lay-filter="submitFilter">立即提交</div>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="../../js/common/jquery-1.11.3.min.js"></script>
<script src="../../layui/layui.js"></script>
<script src="../../js/common/navList.js"></script>
<script src="../../js/common/ajax.js"></script>
<script src="../../js/city-picker.data.js"></script>
<script src="../../js/city-picker.js"></script>
<script src="../../js/main.js"></script>
<script>
    $('#target').citypicker({
    	 province: "江苏省",
  		 city: "常州市",
  		 district: "溧阳市"
    });
    var str = '<span class="select-item" data-count="province" data-code="1">北京市</span><span class="select-item" data-count="city" data-code="2800">北京市</span>'+
    '<span class="select-item" data-count="district" data-code="2849">大兴区</span>';
    $(".city-picker-span span").eq(0).css("display","inline");
	$(".city-picker-span span").eq(0).html(str);
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form,
                layer = layui.layer,
                layedit = layui.layedit,
                laydate = layui.laydate;
//              初始化供应商和设备厂商
		
		ajaxGet({
			url:'manufacturer/getListAll',
			async:true,
			data:{
				maType:1, //1供应商2设备厂商
			},
			successFull: function (res){
			 	console.log(res);
			 	
			 	$.each(res, function(i, item) {
					$("#deviceParentPositionNum").append('<option value="' + item.maAllTitle + '">' + item.maAllTitle + '</option>');
				});
				layui.form.render('select'); //重新渲染select
			},
			errCallBack: function (res) {
				$.each(res, function(i, item) {
					$("#deviceParentPositionNum").append('<option value="' + item.maAllTitle + '">' + item.maAllTitle + '</option>');
				});
				layui.form.render('select'); //重新渲染select
			}
		});
		ajaxGet({
			url:'manufacturer/getListAll',
			async:true,
			data:{
				maType:2, //1供应商2设备厂商
			},
			successFull: function (res){
			 	console.log(res);
			 	$.each(res, function(i, item) {
					$("#deviceProducer").append('<option value="' + item.maAllTitle + '">' + item.maAllTitle + '</option>');
				});
				layui.form.render('select'); //重新渲染select
			},
			errCallBack: function (res) {
				console.log(res);
			 	$.each(res, function(i, item) {
					$("#deviceProducer").append('<option value="' + item.maAllTitle + '">' + item.maAllTitle + '</option>');
				});
				layui.form.render('select'); //重新渲染select
			}
				
		})
        //合同签订时间
        laydate.render({
            elem: '#date'
        });
        //合同有效时间
        laydate.render({
            elem: '#date1'
        });
        //合同有效时间:
        laydate.render({
            elem: '#date2'
        });
        laydate.render({
            elem: '#date3'
        });
        laydate.render({
            elem: '#date4'
        });

        //监听提交
        form.on('submit(submitFilter)', function (data) {
//            console.log(data.field)
            if(data.field.jiqiaddress != ''){
                var address = data.field.jiqiaddress.split("/")[0]+data.field.jiqiaddress.split("/")[2]+data.field.jiqiaddress.split("/")[1];
                var city =  data.field.jiqiaddress.split("/")[1]
                $.ajax({
                    url: 'http://api.map.baidu.com/geocoder/v2/',
                    type:'GET',
                    dataType: "jsonp",
                    data:{
                        address:address,
                        city:city,
                        output:'json',
                        ak:'Dgss6mIeNeCGttMM4llQ3sQGRhGNI8Ai',
                        precise:1
                    },
                    success: function (res){
                        console.log(res)
                        if(res.status == 0) {
                            var lng = res.result.location.lng;
                              var lat =  res.result.location.lat;
                            ajaxPost({
                                url: '/ledger/add',
                                data: {
                                    deviceCode: data.field.jiqicode, //设备编号
                                    deviceName: data.field.jiqiname, //设备名称
                                    deviceType: data.field.jiqiclassfi, //设备类型
                                    deviceStatus: data.field.jiqistatus, //设备状态 0使用中 1禁用
                                    deviceClass: data.field.jiqimodules, //设备分类
                                    deviceBarCode: data.field.jiqiercode, //设备条码
                                    deviceInstallAddress: data.field.jiqiposi,// 安装地址
                                    deviceInstallPosition: data.field.jiqiaddress,//安装位置
                                    deviceModel: data.field.jiqixinghao,//设备型号,
                                    deviceSpec: data.field.jiqiguige,//设备规格,
                                    devicePositionNum: data.field.jiqiweihao,//设备位号,
                                    deviceParentPositionNum: data.field.jiqifuweihao,//设备父位号deviceSupplier;供应商
                                    deviceSupplier: data.field.jiqishanghu,
                                    deviceProducer: data.field.jiqichangshang,//设备厂商
                                    deviceArrivalDate: data.field.daohuoshijian,//到货时间
                                    deviceApplyDate: data.field.shiyongshijian,//使用时间
                                    deviceScrapDate: data.field.baofeishijian,//报废日期
                                    deviceOutFactoryDate: data.field.chuchangriqi,//出厂日期
                                    devicePurpose: data.field.jiqiyongtu,//设备用途
                                    deviceOutFactoryCode: data.field.chuchangbiaohao,//出厂编号
                                    responsibilityDep: data.field.zerenbumen,//责任部门
                                    responsibilityUser: data.field.fuzeren,//责任人
                                    devicePrice: data.field.gouzhijiazhi,//设备价格
                                    deviceDesc: $("#lay_beizhu").val(),//备注
                                    deviceLongitude: lng,//经度
                                    deviceLatitude: lat,//纬度
                                },
                                successFull: function (res) {
                                    console.log(res)
                                    layer.msg('添加成功', {
                                        icon: 6
                                    });
                                    window.location.href = "./accountsList.html?pos=0&childPos=0";
                                },
                                errCallBack: function (res) {
                                    layer.msg(res.msg, {
                                        icon: 6
                                    });
                                }
                            });
                        }else{
                            layer.msg('无效地理位置', {
                                icon: 6
                            });
                        }
                    },
                    error: function (res) {
                        layer.msg('请输入正确的安装位置', {
                            icon: 6
                        });
                    }
                })
            }

        });
    });
</script>
</body>

</html>